package com.example.hibernate.program;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "PROJECTS", schema = "HB")
public class Project implements Serializable {

	private long id;
	private String name;
	private Set<Employee> employees;
	
	public Project() {
		this.employees = new HashSet<Employee>();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PROJECT_ID")
	@Access(AccessType.FIELD)
	public long getId() {
		return id;
	}

	@Column(name = "PROJECT_NAME", nullable = false, length = 200)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToMany
	@JoinTable(name="EMPLOYEES_PROJECTS",
		joinColumns={
			@JoinColumn(name="PROJECT_ID")
		},
		inverseJoinColumns={
			@JoinColumn(name="EMPOYEE_ID")
		},
		schema = "HB"
	)
	public Set<Employee> getEmployees() {
		return employees;
	}
	
	public void setEmployees(Set<Employee> employees) {
		this.employees = employees;
	}
}
